package cn.bgs.controller;


import cn.bgs.common.R;
import cn.bgs.service.IVehicleNumberService;


import cn.bgs.common.R;
import cn.bgs.pojo.VehicleArea;
import cn.bgs.pojo.VehicleNumber;
import cn.bgs.service.IVehicleNumberService;
import cn.bgs.vo.VehicleAdd;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import cn.bgs.vo.CarInfoVo;
import cn.bgs.vo.CwnumVo;
import cn.bgs.vo.UserVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 车位编号表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/vehicle-number")
public class VehicleNumberController {
    @Autowired
    IVehicleNumberService iVehicleNumberService;



    @GetMapping("/appFindVehicleNumber/{vehicleAreaId}")
    @ApiOperation(value = "app我的车位(添加车位信息查询)")
    public R appFindVehicleNumber(@PathVariable Integer vehicleAreaId){

        List<VehicleNumber> vehicleNumber = iVehicleNumberService.appFindVehicleNumber(vehicleAreaId);
        if (vehicleNumber != null){
            return R.ok().data("vehicleNumber",vehicleNumber);
        }else {
            return R.error();
        }
    }

    @PostMapping("/appvehicleFind/{userId}")
    @ApiOperation(value = "app我的车位(车位信息查询)")
    public R appvehicleFind(@PathVariable Integer userId){


        if (userId!=0){
            List<VehicleAdd> vehicleAdds= iVehicleNumberService.appvehicleFind(userId);
            return R.ok().message("修改成功").data("myVehicleInfo",vehicleAdds);
        }else {
            return R.error().message("修改失败，信息有误或者验证码失效");
        }

    }


    @PostMapping("/deleteMyVehicle/{vehicleCarId}")
    @ApiOperation(value = "app我的车位(删除)")
    public R deleteMyVehicle(@PathVariable Integer vehicleCarId){

        System.out.println("------------"+vehicleCarId);

        if (vehicleCarId!=0){
            iVehicleNumberService.deleteMyVehicle(vehicleCarId);
            return R.ok().message("删除成功");
        }else {
            return R.error().message("删除失败");
        }

    }

    //车位全查
    @RequestMapping("/selectnumInfo")
    public R selectnumInfo(@RequestBody CwnumVo cwnumVo){
        return iVehicleNumberService.selectnumInfo(cwnumVo);
    }
    //查询所有用户
    @GetMapping("/selectAllUser")
    public R selectAllUser(UserVo userVo){
        return iVehicleNumberService.selectAllUser(userVo);
    }
    //添加车位信息
    @PostMapping("/insertPcInfo")
    public R insertPcInfo(@RequestBody CwnumVo cwnumVo){
        boolean a = iVehicleNumberService.insertPcInfo(cwnumVo);
        return R.ok().data("data", a);
    }
    //删除车位信息
    @GetMapping("/delPcInfo")
    public R delPcInfo(Integer vehicleNumberId){
        return iVehicleNumberService.delPcInfo(vehicleNumberId);
    }
    //修改车位信息
    @PostMapping("/updatePcInfo")
    public R updatePcInfo(@RequestBody CwnumVo cwnumVo){
        if (iVehicleNumberService.updatePcInfo(cwnumVo)){
            return R.ok();
        }
        return R.error();
    }
    @GetMapping("PcInfo")
    public R PcInfo(CwnumVo cwnumVo){
        return iVehicleNumberService.PcInfo(cwnumVo);
    }

    @RequestMapping("/getPcarInfo")
    public R getPcarInfo(CarInfoVo carInfoVo){
        return iVehicleNumberService.getPcarInfo(carInfoVo);
    }
}
